package com.company.cloud.company.modules.app.controller;

import com.company.cloud.common.asserts.ValidatorUtils;
import com.company.cloud.common.auth.annotation.Login;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.bean.LoginSimpleUserInfo;
import com.company.cloud.common.utils.AuthContextUtils;
import com.company.cloud.company.modules.app.controller.req.ThirdPlatformConfigSave2EditParam;
import com.company.cloud.company.modules.app.service.ThirdPlatformConfigAppService;
import com.company.cloud.company.modules.cache.service.ThirdConfigCacheService;
import com.company.common.server.config.cloud.ProjectConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Log4j2
@Login
@RestController
@RequestMapping("/app/user/thirdPlatformConfig")
@Api(tags="ThirdPlatform_Mgr_公司获客奖励配置信息")
public class ComThirdPlatformConfigMgrController {

    @Autowired
    private ThirdPlatformConfigAppService thirdPlatformConfigAppService;

    @Autowired
    private ThirdConfigCacheService thirdPlatformConfigCacheService;

    @Autowired
    private ProjectConfig projectConfig;


    @PostMapping("/saveOrEdit")
    @ApiOperation(value="新增/修改", response= BaseResult.class)
    public BaseResult save(@RequestBody ThirdPlatformConfigSave2EditParam params) {
        ValidatorUtils.validate(params);

//        LoginThirdChannelEnum

        LoginSimpleUserInfo userInfo = AuthContextUtils.getUser();
        String companyNo=projectConfig.getCompanyNo(userInfo.getCompanyNo());
        params.setCompanyNo(companyNo);
        thirdPlatformConfigAppService.save2Edit(params,userInfo);
        thirdPlatformConfigCacheService.removeThirdPlatformConfigByCache(companyNo,params.getThirdPlatformType());
        return BaseResult.ok();
    }

    @GetMapping("/get")
    @ApiOperation(value="查询", response= BaseResult.class)
    public BaseResult get() {
        LoginSimpleUserInfo userInfo = AuthContextUtils.getUser();
//        return BaseResult.ok(baseProfitMgrService.get(userInfo.getCompanyNo()));
        return BaseResult.ok();
    }




}
